﻿@{
    Layout = null;
}
@*产品调货信息*@
@*<script src="~/Scripts/WebUploader/webuploader.js"></script>*@
<style>
    .myTabs.nav-tabs > li.active > a, .myTabs.nav-tabs > li.active > a:focus, .myTabs.nav-tabs > li.active > a:hover {
        color: #555;
        cursor: default;
        background-color: #fff;
        border: 1px solid #ddd;
        border-bottom-color: transparent;
    }

    #picker input[type="file"] {
        opacity: 0;
    }

    .form-group .form-control p {
        margin: 0;
    }
</style>

<div data-example-id="togglable-tabs">
    <ul class="myTabs nav nav-tabs" role="tablist" style="display:flex;align-items:center">
        <li role="presentation" class="active">
            <a href="#UpCode" id="UpCode-tab" role="tab" data-toggle="tab" aria-controls="UpCode" aria-expanded="true">上传物流码</a>
        </li>
        <li role="presentation" class="">
            <a href="#WriteCode" role="tab" id="WriteCode-tab" data-toggle="tab" aria-controls="WriteCode" aria-expanded="false">填写物流码</a>
        </li>

    </ul>

    <div class="tab-content">
        <div role="tabpanel" class="tab-pane fade active in" id="UpCode" aria-labelledby="UpCode-tab">
            <!--上传物流码-->
            <div class="form-group" style="display:flex;margin-top:30px;">
                <label id="picker" class="btn btn-success">选择文件</label>
                <div class="form-control"></div>
            </div>
            <p class="h2">文档上传须知：</p>
            <p>1. 先排码后导入，可建立无限级别拖标关系, 排码顺序为（一级，二级，三级，.....)</p>
            <p>2. 请上传按模板格式生成的TXT文档</p>
            <div class="row" style="display:flex;justify-content:center">
                <button id="UpLoad" class="btn btn-primary">下一步</button>
            </div>

        </div>
        <form role="tabpanel" class="tab-pane" id="WriteCode" aria-labelledby="WriteCode-tab" onkeydown="if(event.keyCode==13){return false;}">
            <!--填写物流码-->
            <div class="form-group" style="display:flex;margin-top:30px;align-items:center;">
                <label class="btn btn-success">箱码：</label>
                <div class="col-xs-10 col-sm-10 col-md-10 col-lg-10 ">
                    <textarea class="form-control" autocomplete="off" placeholder="格式说明：每行只能输入一个单标，然后以“，”结束。如下所示：
007010019969,007010019969,007010019969,007010019969,
                               " id="BoxCodes" name="SingleCodes" style="height: 148px;margin-left:15px;" onkeypress="javascript: if (event.keyCode == 32) event.returnValue = false;" oninput="this.value = this.value.replace(/[\r\n]/g, ','); this.value = this.value.replace(/^ +| +$/g, '')"></textarea>
                </div>
            </div>
            <div class="row" style="display:flex;justify-content:center">
                <button type="button" class="btn btn-success" id="LittleUpLoad">下一步</button>
            </div>

        </form>


    </div>
</div>
<script>

    $('#WriteCode').bootstrapValidator({
        //group:"#SingleCodesForm",
        fields: {
            SingleCodes: {
                validators: {
                    notEmpty: {
                        message: '箱码不能为空'
                    },
                }
            }
        }
    });


    $(function () {
        GUID = WebUploader.Base.guid();
        var uploader = WebUploader.create({

            // swf文件路径
            swf: '~/Scripts/WebUploader/Uploader.swf',

            // 文件接收服务端。
            // server: 'FleeGoods/PackBoxUploadTxt',
            server: 'DBH/ProcessRequest',
            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: {
                id: '#picker',
                multiple: false
            },
            accept: {
                title: '文本',
                extensions: 'txt',
                mimeTypes: '*.txt'
            },
            chunked: true,//分片处理大文件
            chunkSize: 2 * 1024 * 1024,
            //由于Http的无状态特征，在往服务器发送数据过程传递一个进入当前页面是生成的GUID作为标示
            formData: { guid: GUID },
            fileNumLimit: 2,  //上传文件的数量限制
            compress: false, //图片在上传前不进行压缩
            fileSizeLimit: 6 * 1024 * 1024 * 1024,    // 所有文件总大小限制 6G
            fileSingleSizeLimit: 5 * 1024 * 1024 * 1024,   // 单个文件大小限制 5 G
            threads: 1, //上传并发数
            disableGlobalDnd: true,


        });
        // 当有文件被添加进队列的时候
        uploader.on('fileQueued', function (file) {
            $('#picker').next().append('<div id="' + file.id + '" >' +
                '<span class="info">' + file.name + '</span>' +
                '<p class="state">请点击下一步</p>' +
            '</div>');

            $('#picker').attr('disabled', 'disabled');
            $('#picker input[type="file"]').attr('disabled', 'disabled');
        });
        // 文件上传过程中创建进度条实时显示。
        uploader.on('uploadProgress', function (file, percentage) {
            var $li = $('#' + file.id),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if (!$percent.length) {
                $percent = $('<div class="progress progress-striped active">' +
                  '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                  '</div>' +
                '</div>').appendTo($li).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css('width', percentage * 100 + '%');
        });
        uploader.on('uploadSuccess', function (file, response) {

            $.post("FleeGoods/TranUploadTxt", { filePath: response._raw },
                function (r) {
                    ////跳转页面
                    if (r > 0) {
                        $.MGJ.AdjustCargo.Dialog_EditCargo({ 'ID': r });
                        $.MGJ.AdjustCargo.Dialog_CargoInfoObj.close();
                    } else if (r == -2) {
                        $.L.msgError("该码不属于当前企业！");
                    } else if (r == -3) {
                        $.L.msgError("您尚未权限操作该码！");
                    }
                    else if (r == -4) {
                        $.L.msgError("码已被冻结！");
                    }
                    else if (r == -5) {
                        $.L.msgError("当前身份不能做调货！");
                    }
                    else {
                        $.L.msgError("存在没有入库的码！");
                    }
                });
        });

        uploader.on('uploadError', function (file) {
            $('#' + file.id).find('p.state').text('上传出错');
        });
        uploader.on('error', function () {
            $.L.msgError("格式有误,请上传TXT文件！");
        })

        uploader.on('uploadComplete', function (file) {
            $('#' + file.id).find('.progress').fadeOut();
        });
        $('#UpLoad').click(function () {
            uploader.upload();
        })
        //少量上传
        $('#LittleUpLoad').click(function () {
            $('#LittleUpLoad').click(function () {
                var bootstrapValidator = $("#WriteCode").data('bootstrapValidator').validate();
                if (bootstrapValidator.isValid()) {
                    $.MGJ.AdjustCargo.Ajax_Little();
                }
                else {
                    $.L.msgError("请检查数据格式！");
                };
            })

        })
    });


</script>

